import { createApp } from 'vue'
const requireFiles = require.context('.', true, /\.ts$/)
const componentsContext = require.context('@/components/', true, /\.ts$/)

export function loadAllPlugins (app: ReturnType<typeof createApp>) {
  requireFiles.keys().forEach(item => {
    if (typeof requireFiles(item).default === 'function') {
      if (item !== './index.ts') {
        requireFiles(item).default(app)
      }
    }
  })

  // 自定义组件
  componentsContext.keys().forEach(item => {
    const component = componentsContext(item).default
    if (component.componentName) {
      app.component(component.componentName, component)
    }
  })
}
